package loja.view.editor.components.panel;

import static loja.view.editor.components.StatesEditor.CANCEL;
import static loja.view.editor.components.StatesEditor.EDIT;
import static loja.view.editor.components.StatesEditor.END;
import static loja.view.editor.components.StatesEditor.INCLUDE;
import static loja.view.editor.components.StatesEditor.REMOVE;
import static loja.view.editor.components.StatesEditor.SAVE;
import static loja.view.editor.components.StatesEditor.START;
import static loja.view.editor.components.StatesEditor.setStateForComponentEditor;

import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;

import loja.model.handler.HandlerViewEntity;
import loja.view.editor.components.ComponentEditor;
import loja.view.editor.components.ContainerEditor;
import net.miginfocom.swing.MigLayout;

public abstract class EntityPanelEditor<T, PK> extends JPanel implements
		ContainerEditor {

	private static final long serialVersionUID = 1L;

	private List<ComponentEditor> componentsEditor;
	protected HandlerViewEntity<T, PK> handlerViewEntity;

	public EntityPanelEditor(HandlerViewEntity<T, PK> handlerViewEntity) {
		this.handlerViewEntity = handlerViewEntity;
		componentsEditor = new ArrayList<>();
		setLayout(new MigLayout("", "[]8[]", "[]8[]"));
	}

	@Override
	public void onCancel() {
		setStateForComponentEditor(componentsEditor, CANCEL);
	}

	@Override
	public void onEdit() {
		setStateForComponentEditor(componentsEditor, EDIT);
	}

	@Override
	public void onEnd() {
		setStateForComponentEditor(componentsEditor, END);
	}

	@Override
	public void onInclude() {
		setStateForComponentEditor(componentsEditor, INCLUDE);
	}

	@Override
	public void onRemove() {
		setStateForComponentEditor(componentsEditor, REMOVE);
	}

	@Override
	public void onSave() {
		setStateForComponentEditor(componentsEditor, SAVE);
	}

	@Override
	public void onStart() {
		setStateForComponentEditor(componentsEditor, START);
	}

	@Override
	public void addComponentEditor(ComponentEditor componentEditor) {
		componentsEditor.add(componentEditor);

	}

	@Override
	public void removeComponentEditor(ComponentEditor componentEditor) {
		componentsEditor.remove(componentEditor);
	}

}
